Skip to content

Server validation#546

Closed
adwsingh wants to merge 1 commit intomainfrom
server-validation
Closed

Server validation#546
adwsingh wants to merge 1 commit intomainfrom
server-validation

Conversation

@adwsingh
Copy link
Contributor

@adwsingh adwsingh commented Jan 2, 2025

  • WIP
  • WIP. Only maps not working

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

validator.pushPath(member.memberName());
validator.writeBlob(member, value);
validator.popPath();
if (value != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the contract of our shape serializers is that shapes are never supposed to serialize a null value like this. They have to use writeNull to explicitly write a null value. It seems like a bug in whatever code is serializing nulls.


public void startMap(Schema schema) {
checkType(schema, ShapeType.MAP);
if (schema.isMember()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the old implementation, I pushed and popped members names in the list/map/struct implementaitons to avoid these conditionals. Can we no do that anymore?


public void validateByte(Schema schema, byte value) {
currentPresenceTracker.setMember(schema);
pushPath(schema.memberName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the old implementation, you could validate anything, even root level shapes. It looks like this no longer supports that use case.

writer.putContext("collections", Collections.class);
writer.write(
"this.${memberName:L} = ${?nullable}builder.${memberName:L} == null ? null : ${/nullable}${collections:T}.${wrapper:L}(builder.${memberName:L});");
"this.${memberName:L} = builder.${memberName:L} == null ? null : ${collections:T}.${wrapper:L}(builder.${memberName:L});");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null checks are already present in the builder and we need to be able to construct a POJO with null lists during deserialization.

writer.putContext("memberName", symbolProvider.toMemberName(member));
var memberName = symbolProvider.toMemberName(member);
var builderMethodName = memberName;
if (isTracked || requiresNullCheck) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all feels like it really needs some comments to explain what's going on

@Override
public ${shape:N} build() {${?hasRequiredMembers}
tracker.validate();${/hasRequiredMembers}
if (!disableChecks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this and how does it work? Can you now create shapes that don't validate required members are present (so for example, an int gets initialized to 0 implicitly even when it was required but not set)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to disable the checks in the builder if we are in deserialization mode.

job.setFailure(t);
return job.chosenProtocol().serializeError(job, t);
var failure = unwrap(t);
LOGGER.error("Failure while orchestration", failure);
Copy link
Member

@mtdowling mtdowling Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOGGER.error("Failure while orchestration", failure);
LOGGER.error("Failure while orchestrating", failure);

@@ -22,8 +22,8 @@
public final class RequestDeserializer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the javadoc above still valid? What is the change you made here?


package software.amazon.smithy.java.core.serde;

public interface ValidatingShapeDeserializer extends ShapeDeserializer {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used anywhere

}
}

public <T extends SerializableStruct> List<ValidationError> deserializeAndValidate(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this designed to only be used by things like protocols and codecs? Or is this now the only way to create a shape that makes sure required members don't get default values?

}
}

public void startList(Schema schema) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you implement unique items validation yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet.

@adwsingh adwsingh changed the title server validation Server validation Jan 8, 2025
@adwsingh adwsingh force-pushed the server-validation branch 2 times, most recently from 4277887 to 035b3f1 Compare January 8, 2025 22:39
WIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants